package com.yuan.model_convenient.rest;


import com.yuan.model_common.dto.CommonQueryCriteria;
import com.yuan.model_convenient.domain.ConvenientRepair;
import com.yuan.model_convenient.service.ConvenientRepairService;
import com.yuan.model_convenient.service.dto.ConvenientRepairDto;
import com.yuan.model_convenient.service.dto.ConvenientRepairQueryCriteria;
import com.yuan.model_lease.service.dto.LeaseRecordsDto;
import com.yuan.model_lease.service.dto.LeaseRecordsQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.utils.PageResult;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Api(tags = "物业便民: 小区报修管理")
@RestController
@RequestMapping("/api/convenientRepair")
@RequiredArgsConstructor
public class ConvenientRepairController {

    private final ConvenientRepairService ConvenientRepairService;

    @ApiOperation("导出/convenient/repair")
    @GetMapping(value = "/download")
    public void exportRepair(HttpServletResponse response, CommonQueryCriteria criteria) throws IOException {
//        ConvenientRepairService.download(ConvenientRepairService.queryAll(criteria), response);
    }

    @GetMapping("/findList")
    @Log("查询/api/convenient/repair")
    @ApiOperation("查询/api/convenient/repair")
    public ResponseEntity<PageResult<ConvenientRepairDto>> queryRepairList(int page, int size) {
        Pageable pageable = PageRequest.of(page, size);
        PageResult<ConvenientRepairDto> ConvenientRepairDtoPageResult = ConvenientRepairService.queryAll(pageable);
        return new ResponseEntity<>(ConvenientRepairDtoPageResult, HttpStatus.OK);
    }

    @GetMapping("/findListByType")
    @Log("查询/api/lease/records/type")
    @ApiOperation("查询/lease/records/type")
    public ResponseEntity<PageResult<ConvenientRepairDto>> findListByType(ConvenientRepairQueryCriteria criteria, Pageable pageable) {
        PageResult<ConvenientRepairDto> convenientRepairDtoPageResult = ConvenientRepairService.queryAllByType(criteria, pageable);
        return new ResponseEntity<>(convenientRepairDtoPageResult, HttpStatus.OK);
    }


    @Log("新增/api/convenient/repair")
    @ApiOperation("新增/api/convenient/repair")
    @PostMapping("/create")
    public ResponseEntity<Object> createRepair(@Validated @RequestBody ConvenientRepair resources) {
        ConvenientRepairService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("修改/api/convenient/repair")
    @ApiOperation("修改/api/convenient/repair")
    @PostMapping("/update")
    public ResponseEntity<Object> updateRepair(@Validated @RequestBody ConvenientRepair resources) throws Exception {
        ConvenientRepairService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除/api/convenient/repair")
    @ApiOperation("删除/api/convenient/repair")
    @PostMapping("/delete")
    public ResponseEntity<Object> deleteRepair(@RequestParam Integer ids) {
        ConvenientRepairService.delete(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

}
